package main.Game;

@SuppressWarnings("rawtypes")
public class Board implements java.lang.Comparable, Cloneable {
    
	public int     num;
    public Color   color;
	public boolean hide;

	public Board() {
		color   =   Color.white;
		num     =   -1;
		hide    =   true;
	}
	
	/**
	 * 初始化包含各种属性的排
	 * @param color
	 * @param num
	 * @param hide
	 */
	public Board(Color color, int num, boolean hide) {
		this.color  = color;
		this.num    = num;
		this.hide   = hide;
	}
	public Board (int num, Color color) {
		this.color 	= color;
		this.num	= num;
		this.hide	= true;
	}

    /**
     * 改变当前牌的状态
     */
    public void hide() {
        this.hide = false;
    }

    public String toString() {
        return num + "";
    }

    /**
     * 返回处理后的牌
     * @return
     * @throws CloneNotSupportedException
     */
    public Board other_getBoard() throws CloneNotSupportedException {
        Board temp = (Board) this.clone();
        if (hide) {
            temp.num = -1;
        }
        return temp;
    }

    /**
     * 用于Arrays.sort函数
     */
    public int compareTo (Object obj) throws ClassCastException {
        if(!(obj instanceof Board)) {
            throw new ClassCastException("Error Message here.");
        }
        Board b = (Board) obj;
        int temp = this.num - b.num;
        if(temp > 0)
            return -1;
        else if(temp == 0)
            return 0;
        else
            return 1;
    }

    /**
     * 显示牌
     */
    public void show() {
    	if(color == Color.white) {
    		System.out.printf("White %d\n", num);
    	} else {
    		System.out.printf("Black %d\n", num);
    	}
    }

    /**
     * 设置牌
     * @param b
     */
	public void set(Board b) {
		// TODO Auto-generated method stub
		this.num = b.num;
		this.color = b.color;
		this.hide = b.hide;
	}
}

